﻿using System;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;
using BO.News;
using GUI.Extensions;
using ChannelVN.Cached.UrlRewrite;
using ChannelVN.Cached.Base;

namespace GUI.Pages.Sport
{
    public partial class ListNewsAsTimeline : PageBase
    {
        protected override string CacheConfigName
        {
            get
            {
                return "Pages-Sport-ListNewsAsTimeline";
            }
        }

        protected override bool IsCachedChanged(long newsId, string zoneId, long tagId)
        {
            return !string.IsNullOrEmpty(zoneId);
        }

        private const int PageSize = 20;
        public int ZoneId = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            var objCat = RequestExtensions.Category;
            if (objCat != null)
            {
                ZoneId = objCat.Id;

                var bo = CacheSettingExtensions.EnableCacheHtml ? NewsBO_NoCache.GetInstance() : NewsBO.GetInstance();
                var pageIndex = RequestExtensions.PageIndex;
                var dt = bo.GetListNewsWithSubCategory(pageIndex, PageSize, zoneId: objCat.Id);

                ctrListNewsAsTimeline.Visible = ctrListNewsAsTimeline.DataBind(dt);

                
                    ctrPaging.LinkSite = RequestExtensions.Url;
                    ctrPaging.SumPage = bo.GetTotalPagesOfListNews(PageSize, zoneId: objCat.Id);
                    ctrPaging.Padding(pageIndex);


                #region Title/MetaData
                var mtaCategory = NewsBO.GetInstance().GetCategoryMetaData(objCat.Id);
                var extraText = string.Format(" | page {0}", pageIndex);
                if (mtaCategory != null)
                {
                    PresentationUtils.AddMeta(Page, DefinedConstants.MetaAttributes.Description.Id,
                                              DefinedConstants.MetaAttributes.Description.Name, mtaCategory.Description + extraText);
                    PresentationUtils.AddMeta(Page, DefinedConstants.MetaAttributes.Keywords.Id,
                                              DefinedConstants.MetaAttributes.Keywords.Name, mtaCategory.Keywords);
                    PresentationUtils.AddMeta(Page, DefinedConstants.MetaAttributes.NewsKeywords.Id,
                                              DefinedConstants.MetaAttributes.NewsKeywords.Name, mtaCategory.Keywords);
                    Page.Header.Title = string.Format("{0} | soha.vn {1}", mtaCategory.Title, extraText);
                }
                #endregion

                return;

            }
            _301Redirection.RedirectToFileNotFoundPage();
        }
    }
}